package com.wgc.seckill.controller;

import com.wgc.seckill.service.SeckillProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wgc.seckill.domain.SeckillProduct;
import com.itbuka.entity.R;
import com.itbuka.entity.PageResult;
import com.github.pagehelper.Page;

import java.util.List;

/**
 * 秒杀商品表
 */
@RestController
@RequestMapping("/SeckillProduct")
public class SeckillProductController {
    @Autowired
    private SeckillProductService iSeckillProductService;


    /**
    * 查询全部秒杀商品表
    * @param
    * @return
    */
    @GetMapping("/selectAll")
    public R< List<SeckillProduct> > selectAll(){
        return R.ok("查询成功",iSeckillProductService.selectAll());
    }


    /**
     * 条件查询秒杀商品表
     * @param iSeckillProduct
     * @return
     */
    @PostMapping("/selectList")
    public R< List<SeckillProduct> > select(@RequestBody SeckillProduct iSeckillProduct){
        return R.ok("条件查询成功",iSeckillProductService.selectList(iSeckillProduct));
    }

    /**
     * 新增秒杀商品表
     * @param iSeckillProduct
     * @return
     */
    @PostMapping("/insert")
    public R insert(@RequestBody SeckillProduct iSeckillProduct){
        iSeckillProductService.insert(iSeckillProduct);
        return R.ok("新增成功");
    }


    /**
     * 删除秒杀商品表
     * @param ids
     * @return
     */
    @GetMapping("/delete")
    public R delete(@RequestParam String ids){
        iSeckillProductService.delete(ids);
        return R.ok("删除成功");
    }


    /**
     * 修改秒杀商品表
     * @param iSeckillProduct
     * @return
     */
    @PostMapping("/update")
    public R update(@RequestBody SeckillProduct iSeckillProduct){
        iSeckillProductService.update(iSeckillProduct);
        return R.ok("修改成功");
    }

    /**
    * 分页搜索实现秒杀商品表
    * @param page 默认值1
    * @param size 默认值10
    * @return
    */
    @GetMapping(value = "/pageAll" )
    public R pageAll(@RequestParam(defaultValue = "1")  Integer page, @RequestParam(defaultValue = "10") Integer size){
    Page<SeckillProduct> pageList = iSeckillProductService.pageAll(page, size);
        PageResult pageResult=new PageResult(pageList.getTotal(),pageList.getResult());
        return R.ok("查询成功",pageResult);
    }

    /**
    * 分页条件搜索实现秒杀商品表
    * @param iSeckillProduct
    * @param page
    * @param size
    * @return
    */
    @GetMapping(value = "/pageList" )
    public R pageList(@RequestBody SeckillProduct iSeckillProduct,@RequestParam(defaultValue = "1")  Integer page, @RequestParam(defaultValue = "10") Integer size){
    Page<SeckillProduct> pageList = iSeckillProductService.pageList(iSeckillProduct,page, size);
        PageResult pageResult=new PageResult(pageList.getTotal(),pageList.getResult());
        return R.ok("查询成功",pageResult);
    }
}




